﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using IHISCETeim.Library;
using System.Data.Common;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;
using IHISCETeim.Model;

namespace IHISCETeim.DAL
{
    public class AgentPWMacKeepDAL
    {
        public static DataTableCollection AgentPWMacKeep_GetPagination(string whereSql, int PageIndex, int PageSize, string Sort, ref int TotalCount)
        {
            Database DB = DatabaseFactory.CreateDatabase();

            DbCommand dbCommand = DB.GetStoredProcCommand("AgentPWMacKeep_GetPagination");
            DB.AddInParameter(dbCommand, "whereSql", DbType.String, whereSql);
            DB.AddInParameter(dbCommand, "PageIndex", DbType.Int32, PageIndex);
            DB.AddInParameter(dbCommand, "PageSize", DbType.Int32, PageSize);
            DB.AddInParameter(dbCommand, "Sort", DbType.String, Sort);
            DB.AddOutParameter(dbCommand, "TotalCount", DbType.Int32, 8);
            DataTableCollection dt = DB.ExecuteDataSet(dbCommand).Tables;

            TotalCount = Convert.ToInt32(DB.GetParameterValue(dbCommand, "TotalCount"));
            return dt;
        }
        public static int AgentPWMacKeepDetail_Add(int PWUMKID,AgentPWMacKeepDetailInfo obj)
        {
            Database DB = DatabaseFactory.CreateDatabase();

            DbCommand dbCommand = DB.GetStoredProcCommand("AgentPWMacKeepDetail_Add");
            DB.AddInParameter(dbCommand, "PWUMKID", DbType.Int32, PWUMKID);
            DB.AddInParameter(dbCommand, "SerialNumber", DbType.String, obj.SerialNumber);
            DB.AddInParameter(dbCommand, "WorkTime", DbType.Decimal, obj.WorkTime);
            DB.AddInParameter(dbCommand, "KeepDate", DbType.String, obj.KeepDate);
            DB.AddInParameter(dbCommand, "KeepHours", DbType.Int32, obj.KeepHours);
            DB.AddInParameter(dbCommand, "IsKeep", DbType.Boolean, obj.IsKeep);
            DB.AddInParameter(dbCommand, "ScanImg", DbType.String, obj.ScanImg);
            DB.AddInParameter(dbCommand, "JHScanImg", DbType.String, obj.JHScanImg);
            DB.AddInParameter(dbCommand, "TimerScanImg", DbType.String, obj.TimerScanImg);
            DB.AddInParameter(dbCommand, "BYJScanImg", DbType.String, obj.BYJScanImg);
            DB.AddInParameter(dbCommand, "HYScanImg", DbType.String, obj.HYScanImg);
            DB.AddInParameter(dbCommand, "IsSHChange", DbType.Boolean, obj.IsSHChange);
            DB.AddInParameter(dbCommand, "IsSHChangeText", DbType.String, obj.IsSHChangeText);
            DB.AddInParameter(dbCommand, "IsSHWater", DbType.Boolean, obj.IsSHWater);
            DB.AddInParameter(dbCommand, "IsSHWaterText", DbType.String, obj.IsSHWaterText);
            DB.AddInParameter(dbCommand, "IsSHGuiHan", DbType.Boolean, obj.IsSHGuiHan);
            DB.AddInParameter(dbCommand, "IsSHGuiHanText", DbType.String, obj.IsSHGuiHanText);
            DB.AddInParameter(dbCommand, "IsVerify", DbType.Int32, obj.IsVerify);

            //return Convert.ToInt32(DB.ExecuteScalar(dbCommand));
            return Convert.ToInt32(DB.ExecuteScalar(dbCommand));
        }
        public static IDataReader AgentPWMacKeepDetail_GetList(int UMKDID)
        {
            Database DB = DatabaseFactory.CreateDatabase();

            DbCommand dbCommand = DB.GetStoredProcCommand("AgentPWMacKeepDetail_GetList", UMKDID);
            return DB.ExecuteReader(dbCommand);
        }
        public static bool AgentPWMacKeepDetail_Update(int PWUMKID, AgentPWMacKeepDetailInfo obj)
        {
            Database DB = DatabaseFactory.CreateDatabase();

            DbCommand dbCommand = DB.GetStoredProcCommand("AgentPWMacKeepDetail_Update");
            DB.AddInParameter(dbCommand, "PWUMKID", DbType.Int32, PWUMKID);
            DB.AddInParameter(dbCommand, "UMKDID", DbType.Int32, obj.UMKDID);
            DB.AddInParameter(dbCommand, "SerialNumber", DbType.String, obj.SerialNumber);
            DB.AddInParameter(dbCommand, "WorkTime", DbType.Decimal, obj.WorkTime);
            DB.AddInParameter(dbCommand, "KeepDate", DbType.String, obj.KeepDate);
            DB.AddInParameter(dbCommand, "KeepHours", DbType.Int32, obj.KeepHours);
            DB.AddInParameter(dbCommand, "IsKeep", DbType.Boolean, obj.IsKeep);
            DB.AddInParameter(dbCommand, "ScanImg", DbType.String, obj.ScanImg);
            DB.AddInParameter(dbCommand, "JHScanImg", DbType.String, obj.JHScanImg);
            DB.AddInParameter(dbCommand, "TimerScanImg", DbType.String, obj.TimerScanImg);
            DB.AddInParameter(dbCommand, "BYJScanImg", DbType.String, obj.BYJScanImg);
            DB.AddInParameter(dbCommand, "HYScanImg", DbType.String, obj.HYScanImg);
            DB.AddInParameter(dbCommand, "IsSHChange", DbType.Boolean, obj.IsSHChange);
            DB.AddInParameter(dbCommand, "IsSHChangeText", DbType.String, obj.IsSHChangeText);
            DB.AddInParameter(dbCommand, "IsSHWater", DbType.Boolean, obj.IsSHWater);
            DB.AddInParameter(dbCommand, "IsSHWaterText", DbType.String, obj.IsSHWaterText);
            DB.AddInParameter(dbCommand, "IsSHGuiHan", DbType.Boolean, obj.IsSHGuiHan);
            DB.AddInParameter(dbCommand, "IsSHGuiHanText", DbType.String, obj.IsSHGuiHanText);
            DB.AddInParameter(dbCommand, "IsVerify", DbType.Int32, obj.IsVerify);

            try
            {
                DB.ExecuteScalar(dbCommand);
                return true;
            }
            catch (Exception exc)
            {
                return false;
            }
        }
    }
}
